home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / PASSDK30.ZIP;1 / DISK1.ZIP / PAS / CDROMAPP / CDPLAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  3.3 KB  |  146 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4.  
  5. #define OKAY 0
  6.  
  7. #include "cdmaster.h"
  8.  
  9. char *syntax=
  10.     "Syntax: cdplay [drive# [starttrack# [endtrack#]]].\n"
  11.     "\tdrive#\tnumber of CDROM drive;  defaults to the first drive#\n"
  12.     "\t\tuse '.' to specify the first drive# when specifying track#'s.\n"
  13.     "\tstarttrack#\tstarting track number to play.\n"
  14.     "\tendtrack#\tending track number to play.\n"
  15.     "\t\tuse -1 to play to end of disc, -2 to play to end of track.\n";
  16. char *nodrives= "No CDROM drives attached.\n";
  17. char *nomscdex= "MSCDEX is not installed.\n";
  18.  
  19. char *copyright= "cdplay.exe - Copyright Media Vision, 1992\n";
  20. char *programmer= "Bart Crane";
  21.  
  22. main(int argc, char **argv)
  23. {
  24.     int bgntrack= 1;
  25.     int endtrack= 1;
  26.     int numcdroms= 0;
  27.     int ourdrive= 0;
  28.     struct cdtable *cdt;
  29.  
  30.     if (!ismscdex())
  31.         {
  32.         fprintf(stderr, nomscdex);
  33.         return(1);
  34.         }
  35.  
  36.     if (!(numcdroms= getnumcdroms()))
  37.         {
  38.         fprintf(stderr, nodrives);
  39.         return(2);
  40.         }
  41.  
  42.     switch (argc)
  43.         {
  44.         case 4:
  45.             endtrack= atoi(argv[3]);
  46.         case 3:
  47.             bgntrack= atoi(argv[2]);
  48.         case 2:
  49.             if (argv[1][0] != '.')
  50.                 {
  51.                 if (!(ourdrive= atoi(argv[1])))
  52.                     {
  53.                     fprintf(stderr, syntax);
  54.                     return(3);
  55.                     }
  56.                 break;
  57.                 }
  58.  
  59.         case 1:
  60.             if (!(ourdrive= getfirstcdrom()))
  61.                 {
  62.                 fprintf(stderr, nodrives);
  63.                 return(4);
  64.                 }
  65.             break;
  66.  
  67.         default:
  68.             fprintf(stderr, syntax);
  69.             return(5);
  70.         }
  71.  
  72.     if (endtrack == -1)
  73.         endtrack= 99;
  74.     else
  75.     if (endtrack == -2)
  76.         endtrack= bgntrack;
  77.     else
  78.     if (endtrack < bgntrack)
  79.         endtrack= bgntrack;
  80.  
  81.     /* Programming Notes:
  82.     *    Call "createaudiotoc()" to get a quick structure allocated.
  83.     *
  84.     *    Get the trackinfo for the desired track.  Convert the
  85.     *    frame/min/sec/unknown bytes in trackinfo (the starting address)
  86.     *    to a long by getting the address of the frame member and calling
  87.     *    "redtolong()" using a pointer, but subtract 2 seconds from this
  88.     *    value (150 frames);  it is not known why, but if you use the
  89.     *    "starting address" as returned by the driver you actually address
  90.     *    data 2 seconds into the disc (this is required here because
  91.     *    "cdtrackinfo()" is a low level call (cdrom.c) and returns exactly
  92.     *    what the driver provides, whereas "gettrackframes()" (cdmaster.c)
  93.     *    does the adjustment for us.
  94.     *
  95.     *    Then, accumulate the count of frames to play for each track in the
  96.     *    range specified on the command line.
  97.     *
  98.     *    Finally, "cdplay()".
  99.     */
  100.  
  101.     if (cdt= createaudiotoc(ourdrive))
  102.         {
  103.         int status= 0;
  104.         long sframe;
  105.         long tframes= 0;
  106.         int track= bgntrack;
  107.         struct trackinfo ti;
  108.  
  109.         if (status= cdtrackinfo(ourdrive, bgntrack, &ti) >= 0)
  110.             {
  111.             long *redaddress= (long *) &ti.frame;
  112.             long sframe= redtolong((*redaddress)); //- (75* 2);
  113.  
  114.             do
  115.                 {
  116.                 long f= gettrackframes(ourdrive, track);
  117.  
  118.                 if (f == -1)
  119.                     status= -1;
  120.                 else
  121.                 if (!f)
  122.                     if (endtrack != 99)
  123.                         status= -1;
  124.                     else
  125.                         break;
  126.                 if (status < 0)
  127.                     break;
  128.                 tframes+= f;
  129.                 }
  130.             while (++track <= endtrack);
  131.  
  132.             printf("play drive: %2d - From: %2d - Upto: %2d ", ourdrive, bgntrack, track- 1);
  133.  
  134.             if (status >= 0)
  135.                 status= cdplay(ourdrive, sframe, tframes);
  136.             }
  137.         printf("= %X.\n", status);
  138.         destroyaudiotoc(ourdrive);
  139.         }
  140.     else
  141.         printf("failed, no initialization.\n");
  142.  
  143.     return(OKAY);
  144. }
  145.  
  146.